using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Weight.Base
{
    public class RegHelper
    {

        /// <summary>
        /// 判断是否是整数
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static  bool isInteger(string str)
        {
            char[] arr = str.ToCharArray();
            foreach (char item in arr)
            {
                if (item > '9' || item < '0')
                {
                    return false;
                }

            }

            return true;

        }
        /// <summary>
        /// 判断是否为数字
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        static public  bool isNumber(string str)
        {
            bool hasDot = false;
            if (str == null || str.Length == 0)
            {
                return false;
            }
            else
            {
                char[] chr = str.ToCharArray();
                char item;
                for (int index = 0; index < chr.Length; index++)
                {
                    item = chr[index];
                    if (index == 0)
                    {
                        if ( item < '0' || item > '9')
                        {
                            if (item != '-')
                            {
                                return false;
                            }
                        }
                    }
                    else if (index == chr.Length - 1)
                    {
                        if (item < '0' || item > '9')
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (item < '0' || item > '9')
                        {
                            if (item != '.')
                            {
                                return false;
                            }
                            else
                            {
                                if (hasDot) return false;
                                hasDot = true;
                            }
                        }
                    }
                    
                }

                return true;
            }
        }
    }
}


